%Calculate the Extended Matrix of matrix A as single matrix.
%
%Calculate the Extended Matrix of matrix A as single matrix where n is the
%degree of A and m is the degree of the state vector x in homogeneous form.
%
%Prototype: [Ae] = extendedMatrix(A, n, m, hState, d)
%
%Input:     A - nxn matrix with Syms affine parameters.
%           n - Degree of A.
%           m - Degree of the state vector x in homogeneous form.
%           hState - Homogeneous state vector.
%           d - Dimension of homogeneous state vector hState.
%
%Output:    newA - Extended Affine Matrix A as single matrix

function [ Ae ] = extendedMatrix( A, n, m, hState, d )

syms x;
for i = 1:n
    x(i) = ['x_' int2str(i)];
end

for i = 1:n
    xdiff(:,i) = diff(hState, x(i));
end

clear x;
syms x;

for i = 1:n
    x(i,1) = ['x_' int2str(i)];
end

result = expand(xdiff*A*x);

syms Ae;
for i = 1:length(result)
    for j = 1:length(hState)
        chr = char(expand(result(i)/hState(j)));
        Ae(i, j) = getCoefficientFromString(chr);
    end
end

return;

end
